package com.knowledge.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;

import com.knowledge.common.annotation.Log;
import com.knowledge.common.core.controller.BaseController;
import com.knowledge.common.core.domain.AjaxResult;
import com.knowledge.common.enums.BusinessType;
import com.knowledge.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.knowledge.business.domain.TQuestion;
import com.knowledge.business.service.ITQuestionService;
import com.knowledge.common.core.page.TableDataInfo;

/**
 * 常见问题Controller
 *
 * @author zhaoyk
 * @date 2025-09-17
 */
@RestController
@RequestMapping("/business/question")
public class TQuestionController extends BaseController {
    @Autowired
    private ITQuestionService tQuestionService;

/**
 * 查询常见问题列表
 */
//@RequiresPermissions("business:question:list")
@GetMapping("/list")
    public TableDataInfo list(TQuestion tQuestion) {
        startPage();
        List<TQuestion> list = tQuestionService.selectTQuestionList(tQuestion);
        return getDataTable(list);
    }

    /**
     * 导出常见问题列表
     */
    //@RequiresPermissions("business:question:export")
    @Log(title = "常见问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TQuestion tQuestion) {
        List<TQuestion> list = tQuestionService.selectTQuestionList(tQuestion);
        ExcelUtil<TQuestion> util = new ExcelUtil<TQuestion>(TQuestion. class);
        util.exportExcel(response, list, "常见问题数据");
    }

    /**
     * 获取常见问题详细信息
     */
    //@RequiresPermissions("business:question:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(tQuestionService.getById(id));
    }

    /**
     * 新增常见问题
     */
    //@RequiresPermissions("business:question:add")
    @Log(title = "常见问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TQuestion tQuestion) {
        return toAjax(tQuestionService.save(tQuestion));
    }

    /**
     * 修改常见问题
     */
    //@RequiresPermissions("business:question:edit")
    @Log(title = "常见问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TQuestion tQuestion) {
        return toAjax(tQuestionService.updateById(tQuestion));
    }

    /**
     * 删除常见问题
     */
    //@RequiresPermissions("business:question:remove")
    @Log(title = "常见问题", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tQuestionService.removeByIds(Arrays.asList(ids)));
    }
}
